/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package test.entities;

import java.io.Serializable;
import java.math.BigDecimal;
import java.util.Collection;
import java.util.Date;
import javax.persistence.*;
import javax.xml.bind.annotation.XmlRootElement;
import javax.xml.bind.annotation.XmlTransient;

/**
 *
 * @author Issam
 */
@Entity
@Table(name = "ACTION", catalog = "", schema = "NETTRADING")
@XmlRootElement
@NamedQueries({
    @NamedQuery(name = "Action.findAll", query = "SELECT a FROM Action a"),
    @NamedQuery(name = "Action.findByNumAction", query = "SELECT a FROM Action a WHERE a.numAction = :numAction"),
    @NamedQuery(name = "Action.findByValeurCourante", query = "SELECT a FROM Action a WHERE a.valeurCourante = :valeurCourante"),
    @NamedQuery(name = "Action.findByDateEmission", query = "SELECT a FROM Action a WHERE a.dateEmission = :dateEmission")})
public class Action implements Serializable {
    private static final long serialVersionUID = 1L;
    @Id
    @Basic(optional = false)
    @Column(name = "NUM_ACTION", nullable = false)
    @GeneratedValue(strategy= GenerationType.AUTO)
    private Long numAction;
    // @Max(value=?)  @Min(value=?)//if you know range of your decimal fields consider using these annotations to enforce field validation
    @Basic(optional = false)
    @Column(name = "VALEUR_COURANTE", nullable = false, precision = 7, scale = 3)
    private BigDecimal valeurCourante;
    @Basic(optional = false)
    @Column(name = "DATE_EMISSION", nullable = false)
    @Temporal(TemporalType.TIMESTAMP)
    private Date dateEmission;
    @JoinTable(name = "ACHAT_ACTION", joinColumns = {
        @JoinColumn(name = "NUM_ACTION", referencedColumnName = "NUM_ACTION", nullable = false)}, inverseJoinColumns = {
        @JoinColumn(name = "NUM_ACHAT", referencedColumnName = "NUM_ACHAT", nullable = false)})
    @ManyToMany
    private Collection<OrdreAchat> ordreAchatCollection;
    @JoinTable(name = "VENTE_ACTION", joinColumns = {
        @JoinColumn(name = "NUM_ACTION", referencedColumnName = "NUM_ACTION", nullable = false)}, inverseJoinColumns = {
        @JoinColumn(name = "NUM_VENTE", referencedColumnName = "NUM_VENTE", nullable = false)})
    @ManyToMany
    private Collection<OrdreVente> ordreVenteCollection;
    @OneToMany(cascade = CascadeType.ALL, mappedBy = "action")
    private Collection<PortefeuilleAction> portefeuilleActionCollection;
    @JoinColumn(name = "ID_ENTREPRISE", referencedColumnName = "ID_ENTREPRISE", nullable = false)
    @ManyToOne(optional = false)
    private Entreprise idEntreprise;
    @OneToMany(cascade = CascadeType.ALL, mappedBy = "numAction")
    private Collection<HistoriqueAction> historiqueActionCollection;

    public Action() {
    }

    public Action(Long numAction) {
        this.numAction = numAction;
    }

    public Action(Long numAction, BigDecimal valeurCourante, Date dateEmission) {
        this.numAction = numAction;
        this.valeurCourante = valeurCourante;
        this.dateEmission = dateEmission;
    }

    public Long getNumAction() {
        return numAction;
    }

    public void setNumAction(Long numAction) {
        this.numAction = numAction;
    }

    public BigDecimal getValeurCourante() {
        return valeurCourante;
    }

    public void setValeurCourante(BigDecimal valeurCourante) {
        this.valeurCourante = valeurCourante;
    }

    public Date getDateEmission() {
        return dateEmission;
    }

    public void setDateEmission(Date dateEmission) {
        this.dateEmission = dateEmission;
    }

    @XmlTransient
    public Collection<OrdreAchat> getOrdreAchatCollection() {
        return ordreAchatCollection;
    }

    public void setOrdreAchatCollection(Collection<OrdreAchat> ordreAchatCollection) {
        this.ordreAchatCollection = ordreAchatCollection;
    }

    @XmlTransient
    public Collection<OrdreVente> getOrdreVenteCollection() {
        return ordreVenteCollection;
    }

    public void setOrdreVenteCollection(Collection<OrdreVente> ordreVenteCollection) {
        this.ordreVenteCollection = ordreVenteCollection;
    }

    @XmlTransient
    public Collection<PortefeuilleAction> getPortefeuilleActionCollection() {
        return portefeuilleActionCollection;
    }

    public void setPortefeuilleActionCollection(Collection<PortefeuilleAction> portefeuilleActionCollection) {
        this.portefeuilleActionCollection = portefeuilleActionCollection;
    }

    public Entreprise getIdEntreprise() {
        return idEntreprise;
    }

    public void setIdEntreprise(Entreprise idEntreprise) {
        this.idEntreprise = idEntreprise;
    }

    @XmlTransient
    public Collection<HistoriqueAction> getHistoriqueActionCollection() {
        return historiqueActionCollection;
    }

    public void setHistoriqueActionCollection(Collection<HistoriqueAction> historiqueActionCollection) {
        this.historiqueActionCollection = historiqueActionCollection;
    }

    @Override
    public int hashCode() {
        int hash = 0;
        hash += (numAction != null ? numAction.hashCode() : 0);
        return hash;
    }

    @Override
    public boolean equals(Object object) {
        // TODO: Warning - this method won't work in the case the id fields are not set
        if (!(object instanceof Action)) {
            return false;
        }
        Action other = (Action) object;
        if ((this.numAction == null && other.numAction != null) || (this.numAction != null && !this.numAction.equals(other.numAction))) {
            return false;
        }
        return true;
    }

    @Override
    public String toString() {
        return "test.entities.Action[ numAction=" + numAction + " ]";
    }
    
}
